package 湖北工业大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 北京建筑大学.BJjuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HbGu {
    public static void main(String[] args) throws IOException {
        HbGuBean hbGuBean = null;
        List<HbGuBean> hbGuBeans = new ArrayList<>();
        Connection connect = Jsoup.connect("https://eee.hbut.edu.cn/szdw/yjsds1.htm");
        String attr1 = null;
        Document post = connect.post();
        Element element = post.getElementsByTag("table").get(0);
        for (Element a : element.getElementsByTag("a")) {
            hbGuBean = new HbGuBean();
            String attr = a.attr("href");
            attr1 = attr.substring(3, attr.length());
//            System.out.println(attr1);
            Connection connect1 = Jsoup.connect("https://eee.hbut.edu.cn/" + attr1);
            Document post1 = connect1.post();
            Element element2 = post1.getElementsByClass("con_title").get(0);
            hbGuBean.setT_name(element2.text());
            Element element1 = post1.getElementsByClass("v_news_content").get(0);
//            System.out.println(element1.text());
            hbGuBean.setInfo(element1.text());
            hbGuBeans.add(hbGuBean);
        }
        EasyExcel.write("src/HbGu.xlsx", HbGuBean.class).sheet("user").doWrite(hbGuBeans);

    }
}
